package com.movisol.messengercommunicator.data;

import java.io.Serializable;
import java.util.Date;

public class CacheObject implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -758857397365319801L;
	protected Date dateSaved;
	protected Integer timeToLive;
	protected String uri;
	
	public CacheObject(Date dateSaved, CommunicatorUri comUri) {
		super();
		this.dateSaved = dateSaved;
		this.uri = comUri.getUri();
		timeToLive = comUri.getTimeToLive();
	}
	
	public boolean isExpired(){
		 Date today = new Date();
		
		if (dateSaved==null)
			return true;
		else 
		{
			long dateDiff;
			long t2lMilliseconds = timeToLive*1000;
			dateDiff = today.getTime()- (dateSaved.getTime()+t2lMilliseconds);
			if (dateDiff >= 0) 
				return true;
			else 
				return false;
		}
	}

	public Date getDateSaved() {
		return dateSaved;
	}

	public void setDateSaved(Date dateSaved) {
		this.dateSaved = dateSaved;
	}

	public Integer getTimeToLive() {
		return timeToLive;
	}

	public void setTimeToLive(Integer timeToLive) {
		this.timeToLive = timeToLive;
	}

	public String getUri() {
		return uri;
	}

	public void setUri(String uri) {
		this.uri = uri;
	}
	
}
